#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
using namespace std;

class Solution {
public:
    int longestOnes(vector<int>& A, int K) {
        //滑动窗口求解问题
        int SumZero = 0;
        int left = 0;
        int right = 0; 
        int result = 0;
        queue<int> SecondZero; //记录第二个zero的位置
        int size = A.size();
        while(right<size){
            if(A[right]==1){
                
            }
            else{
                ++SumZero;
                
            }
            if(SumZero>K){
                if(SumZero==K+1)
                    result = max(result,right-left);
                if(A[left]==0){
                    --SumZero;
                }
                ++left;
                
            }
            ++right;

        }
        result = max(result,right-left);
        return result;
    }
};

int main(){
    Solution S;
    vector<int> nums = {0,0,1,1,0,0,1,1,1,0,1,1,0,0,0,1,1,1,1};
    cout<<S.longestOnes(nums,3)<<endl;
}